package com.jkhan.demo.date_api;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Demo02 {

    public static void main(String[] args) throws ParseException {

        Date d1 = new Date(System.currentTimeMillis());

        Calendar c1 = Calendar.getInstance();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        System.out.println("格式化前d1 = " + d1.toString());
        System.out.println("格式化后d1 = " + sdf.format(d1));

        String date = "2022-09-29";
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        Date d2 = sdf1.parse(date);
        System.out.println("String转换Date,d2 = " + d2.toString());

        String s1 = sdf1.format(d2);
        System.out.println("Date转换String,s1 = " + s1);

    }
}
